package com.cyl.manager.act.service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cyl.manager.act.mapper.FhRechargeDataMapper;
import com.cyl.manager.act.domain.entity.FhRechargeData;
import com.cyl.manager.act.domain.query.FhRechargeDataQuery;

/**
 * VIP配置表Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class FhRechargeDataService {
    @Autowired
    private FhRechargeDataMapper fhRechargeDataMapper;

    /**
     * 查询VIP配置表
     *
     * @param id VIP配置表主键
     * @return VIP配置表
     */
    public FhRechargeData selectById(Long id) {
        return fhRechargeDataMapper.selectById(id);
    }

    /**
     * 查询VIP配置表列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return VIP配置表
     */
    public List<FhRechargeData> selectList(FhRechargeDataQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<FhRechargeData> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        BigDecimal price = query.getPrice();
        if (price != null) {
            qw.eq("price", price);
        }
        BigDecimal continuousPrice = query.getContinuousPrice();
        if (continuousPrice != null) {
            qw.eq("continuous_price", continuousPrice);
        }
        String type = query.getType();
        if (!StringUtils.isEmpty(type)) {
            qw.eq("type", type);
        }
        BigDecimal originalPrice = query.getOriginalPrice();
        if (originalPrice != null) {
            qw.eq("original_price", originalPrice);
        }
        BigDecimal discountPrice = query.getDiscountPrice();
        if (discountPrice != null) {
            qw.eq("discount_price", discountPrice);
        }
        Integer day = query.getDay();
        if (day != null) {
            qw.eq("day", day);
        }
        String discountText = query.getDiscountText();
        if (!StringUtils.isEmpty(discountText)) {
            qw.eq("discount_text", discountText);
        }
        Integer discountColor = query.getDiscountColor();
        if (discountColor != null) {
            qw.eq("discount_color", discountColor);
        }
        Integer checked = query.getChecked();
        if (checked != null) {
            qw.eq("checked", checked);
        }
        String loginIp = query.getLoginIp();
        if (!StringUtils.isEmpty(loginIp)) {
            qw.eq("login_ip", loginIp);
        }
        LocalDateTime loginDate = query.getLoginDate();
        if (loginDate != null) {
            qw.eq("login_date", loginDate);
        }
        return fhRechargeDataMapper.selectList(qw);
    }

    /**
     * 新增VIP配置表
     *
     * @param fhRechargeData VIP配置表
     * @return 结果
     */
    public int insert(FhRechargeData fhRechargeData) {
        fhRechargeData.setCreateTime(LocalDateTime.now());
        return fhRechargeDataMapper.insert(fhRechargeData);
    }

    /**
     * 修改VIP配置表
     *
     * @param fhRechargeData VIP配置表
     * @return 结果
     */
    public int update(FhRechargeData fhRechargeData) {
        return fhRechargeDataMapper.updateById(fhRechargeData);
    }

    /**
     * 批量删除VIP配置表
     *
     * @param ids 需要删除的VIP配置表主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return fhRechargeDataMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除VIP配置表信息
     *
     * @param id VIP配置表主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return fhRechargeDataMapper.updateDelFlagByIds(ids);
    }
}
